{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "a0657324-1222-4fa0-bc0c-163c928b2c72",
   "metadata": {},
   "source": [
    "# 快速傅里叶变换"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2ee9caa0-4198-4c9b-9e8e-22d21e33c8ca",
   "metadata": {},
   "source": [
    "姓名：石庆波\n",
    "---\n",
    "学号：202052320106\n",
    "---"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "1bd77fef-0f1a-44da-9735-bdc0ff42a3e4",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "findfont: Font family ['sans-serif'] not found. Falling back to DejaVu Sans.\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: SimHei\n",
      "/opt/conda/lib/python3.9/site-packages/matplotlib/backends/backend_agg.py:240: RuntimeWarning: Glyph 21407 missing from current font.\n",
      "  font.set_text(s, 0.0, flags=flags)\n",
      "/opt/conda/lib/python3.9/site-packages/matplotlib/backends/backend_agg.py:240: RuntimeWarning: Glyph 22987 missing from current font.\n",
      "  font.set_text(s, 0.0, flags=flags)\n",
      "/opt/conda/lib/python3.9/site-packages/matplotlib/backends/backend_agg.py:240: RuntimeWarning: Glyph 25391 missing from current font.\n",
      "  font.set_text(s, 0.0, flags=flags)\n",
      "/opt/conda/lib/python3.9/site-packages/matplotlib/backends/backend_agg.py:240: RuntimeWarning: Glyph 24133 missing from current font.\n",
      "  font.set_text(s, 0.0, flags=flags)\n",
      "/opt/conda/lib/python3.9/site-packages/matplotlib/backends/backend_agg.py:240: RuntimeWarning: Glyph 22270 missing from current font.\n",
      "  font.set_text(s, 0.0, flags=flags)\n",
      "findfont: Font family ['sans-serif'] not found. Falling back to DejaVu Sans.\n",
      "findfont: Generic family 'sans-serif' not found because none of the following families were found: SimHei\n",
      "/opt/conda/lib/python3.9/site-packages/matplotlib/backends/backend_agg.py:240: RuntimeWarning: Glyph 21435 missing from current font.\n",
      "  font.set_text(s, 0.0, flags=flags)\n",
      "/opt/conda/lib/python3.9/site-packages/matplotlib/backends/backend_agg.py:240: RuntimeWarning: Glyph 22122 missing from current font.\n",
      "  font.set_text(s, 0.0, flags=flags)\n",
      "/opt/conda/lib/python3.9/site-packages/matplotlib/backends/backend_agg.py:240: RuntimeWarning: Glyph 21518 missing from current font.\n",
      "  font.set_text(s, 0.0, flags=flags)\n",
      "/opt/conda/lib/python3.9/site-packages/matplotlib/backends/backend_agg.py:203: RuntimeWarning: Glyph 21407 missing from current font.\n",
      "  font.set_text(s, 0, flags=flags)\n",
      "/opt/conda/lib/python3.9/site-packages/matplotlib/backends/backend_agg.py:203: RuntimeWarning: Glyph 22987 missing from current font.\n",
      "  font.set_text(s, 0, flags=flags)\n",
      "/opt/conda/lib/python3.9/site-packages/matplotlib/backends/backend_agg.py:203: RuntimeWarning: Glyph 25391 missing from current font.\n",
      "  font.set_text(s, 0, flags=flags)\n",
      "/opt/conda/lib/python3.9/site-packages/matplotlib/backends/backend_agg.py:203: RuntimeWarning: Glyph 24133 missing from current font.\n",
      "  font.set_text(s, 0, flags=flags)\n",
      "/opt/conda/lib/python3.9/site-packages/matplotlib/backends/backend_agg.py:203: RuntimeWarning: Glyph 22270 missing from current font.\n",
      "  font.set_text(s, 0, flags=flags)\n",
      "/opt/conda/lib/python3.9/site-packages/matplotlib/backends/backend_agg.py:203: RuntimeWarning: Glyph 21435 missing from current font.\n",
      "  font.set_text(s, 0, flags=flags)\n",
      "/opt/conda/lib/python3.9/site-packages/matplotlib/backends/backend_agg.py:203: RuntimeWarning: Glyph 22122 missing from current font.\n",
      "  font.set_text(s, 0, flags=flags)\n",
      "/opt/conda/lib/python3.9/site-packages/matplotlib/backends/backend_agg.py:203: RuntimeWarning: Glyph 21518 missing from current font.\n",
      "  font.set_text(s, 0, flags=flags)\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAtIAAAEICAYAAAByJxN+AAAAOXRFWHRTb2Z0d2FyZQBNYXRw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wa+BDzc+vmqYcTeTR6tdVuBv2PujM9a59Ehr0tb//4PAHcD/7JtXce8RuE24rF3nBuj8H5qxXkjc38+O9KaJ+9fKnbgN1qv0yRwwbDj7yKX/wPsB77aKsQbRyGXFeTciJq9VC6tddbtGt1GNe5W7Nbsmtz6XbP9inBJkiSpQB1PNpQkSZJqz0ZakiRJKmAjLUmSJBWwkZYkSZIK2EhLkiRJBWykJUmSpAI20pIkSVKB/w8SZHjO/5W8UQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 864x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 导入所需的库\n",
    "import numpy as np # 用于进行数学计算\n",
    "import matplotlib.pyplot as plt # 用于绘制图形\n",
    "import math # 用于数学计算\n",
    "\n",
    "plt.rcParams['font.sans-serif'] = ['SimHei']  # 用来正常显示中文标签\n",
    "plt.rcParams['axes.unicode_minus'] = False  # 用来正常显示负号\n",
    "\n",
    "# 定义一个函数，用于生成正弦波\n",
    "def getSin(amp, freq, phase, sampleList):\n",
    "    return amp * np.sin(-2 * math.pi * freq * sampleList + phase)\n",
    "\n",
    "# 定义一个函数，用于生成余弦波\n",
    "def getCos(amp, freq, phase, sampleList):\n",
    "    return amp * np.cos(-2 * math.pi * freq * sampleList + phase)\n",
    "\n",
    "# 定义去噪函数，将振幅小于阈值的噪声去除\n",
    "def denoise(arr, thresh):\n",
    "    mask = arr > thresh\n",
    "    return mask * arr\n",
    "\n",
    "# 设置采样率为 3000\n",
    "srate = 3000\n",
    "\n",
    "# 在 0 到 1 的范围内生成等间距的采样点\n",
    "t = np.linspace(0, 1, srate)\n",
    "\n",
    "# 生成四个正弦和余弦波\n",
    "s1 = getSin(amp=1.5, freq=30, phase=0, sampleList=t)\n",
    "s2 = getCos(amp=3, freq=5, phase=0, sampleList=t)\n",
    "s3 = getSin(amp=10, freq=100, phase=0, sampleList=t)\n",
    "s4 = getCos(amp=20, freq=120, phase=0, sampleList=t)\n",
    "\n",
    "# 将四个正弦和余弦波相加，得到混合信号\n",
    "mixed_signal = s1 + s2 + s3 + s4\n",
    "\n",
    "# 使用 numpy 的 fft 函数计算傅里叶系数\n",
    "fCoefs = np.fft.fft(mixed_signal, srate)\n",
    "\n",
    "# 计算振幅列表\n",
    "amp_list = 2 * np.abs(fCoefs / srate)\n",
    "\n",
    "# 将振幅数组和频率数组进行平移，使 0 Hz 位于中心\n",
    "freqs = np.fft.fftfreq(len(amp_list), 1/srate)\n",
    "amp_shifted = np.fft.fftshift(amp_list)\n",
    "freq_shift = np.fft.fftshift(freqs)\n",
    "\n",
    "# 创建两个子图，分别用于显示原始振幅频谱和处理后的振幅频谱\n",
    "fig, ax = plt.subplots(1, 2, figsize=(12, 4))\n",
    "\n",
    "# 绘制原始振幅频谱\n",
    "ax[0].set_title('原始振幅图')\n",
    "ax[0].stem(freq_shift, amp_shifted)\n",
    "ax[0].set_xlim([-150, 150])\n",
    "ax[0].set_ylim([-0.5, 21])\n",
    "ax[0].grid()\n",
    "\n",
    "# 对振幅频谱进行去噪处理\n",
    "amp_shifted[(freq_shift > 110) | (freq_shift < -110)] = 0\n",
    "amp_shifted = denoise(amp_shifted, 1)\n",
    "\n",
    "# 绘制处理后的振幅频谱\n",
    "ax[1].set_title('去噪后振幅图')\n",
    "ax[1].stem(freq_shift, amp_shifted)\n",
    "\n",
    "# 设置第二个子图的坐标轴范围\n",
    "ax[1].set_xlim([-150, 150])\n",
    "ax[1].set_ylim([-0.5, 21])\n",
    "\n",
    "# 给第二个子图添加网格线\n",
    "ax[1].grid()\n",
    "\n",
    "# 显示图形\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7ff863f9-d195-4a87-bfed-b2e747231433",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
